local extension = Package:new("wq_pohuai")
extension.extensionName = "FkWqmt"
Fk:loadTranslationTable{
  ["wq_pohuai"] = "无期迷途·破坏",
}

local Wqc = require "packages/FkWqmt/wq_common"

-- 禁闭者：卓娅
local wq_zhuoya = General:new(extension, "wq_zhuoya", "qun", 4, 4, General.Female)
-- 技能：侵略
local wq_skill_qinlue = fk.CreateTriggerSkill{
  name = "wq_skill_qinlue",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase ~= Player.NotActive and data.card.trueName == "slash" and player:usedCardTimes("slash", Player.HistoryTurn) == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "wq_skill_qinlue_count", 1)
  end,
}
local wq_skill_qinlue_buff = fk.CreateTargetModSkill{
  name = "#wq_skill_qinlue_buff",
  anim_type = "offensive",
  residue_func = function(self, player, skill, scope, card)
    return (player:hasSkill("wq_skill_qinlue") and skill.trueName == "slash_skill") and player:getMark("wq_skill_qinlue_count") or 0
  end,
}
wq_skill_qinlue:addRelatedSkill(wq_skill_qinlue_buff)
-- 技能：军临
local wq_skill_junlin = fk.CreateTriggerSkill{
  name = "wq_skill_junlin",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(
      table.filter(room:getOtherPlayers(player), function(p) return player:inMyAttackRange(p) end), Util.IdMapper
    ), 1, 1, "#wq_skill_junlin-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dest = room:getPlayerById(self.cost_data)
    room:damage{
      from = player,
      to = dest,
      damage = 1,
      skillName = self.name,
    }
    if dest:isAlive() then
      room:addPlayerMark(dest, "@wq_mark_kongju", 1)
    end
  end,
}
-- 技能：高武
local wq_skill_gaowu = fk.CreateTriggerSkill{
  name = "wq_skill_gaowu",
  anim_type = "offensive",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) and target and player == target and player.phase == Player.Play then
      if data.to and player.id ~= data.to.id then
        room:addPlayerMark(data.to, "wq_skill_gaowu_damage_"..player.id, 1)
        return data.to:getMark("wq_skill_gaowu_damage_"..player.id) > 1 and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, data, "#wq_skill_gaowu_prompt::"..data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(data.to, 1, self.name)
  end,
  refresh_events = {fk.EventPhaseEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target and player == target and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    table.forEach(room:getAlivePlayers(), function(p)
      room:setPlayerMark(p, "wq_skill_gaowu_damage_"..player.id, 0)
    end)
  end,
}
-- 卓娅的技能
wq_zhuoya:addSkill(wq_skill_qinlue)
wq_zhuoya:addSkill(wq_skill_junlin)
wq_zhuoya:addSkill(wq_skill_gaowu)
-- 卓娅的翻译
Fk:loadTranslationTable{
  ["wq_zhuoya"] = "卓娅",
  ["#wq_zhuoya"] = "超限暴力",
  ["designer:wq_zhuoya"] = "妙霄",
  ["cv:wq_zhuoya"] = "官方",
  ["illustrator:wq_zhuoya"] = "官方",
  ["wq_skill_qinlue"] = "侵略",
  [":wq_skill_qinlue"] = "锁定技，你的回合内当你首次使用【杀】时，你于每个出牌阶段使用【杀】的限制次数+1。",
  ["$wq_skill_qinlue"] = "你们找错了对手。",
  ["wq_skill_junlin"] = "军临",
  [":wq_skill_junlin"] = "出牌阶段开始时，你可以对攻击范围内的一名其他角色造成1点伤害，然后令其获得1枚「恐惧」标记。"
  ..Wqc.getTranslateInNewLine("#wq_common_mark_kongju_description"),
  ["#wq_skill_junlin-choose"] = "军临：你可以对攻击范围内的一名其他角色造成1点伤害，然后令其获得1枚「恐惧」标记",
  ["$wq_skill_junlin"] = "我，即是军团！",
  ["wq_skill_gaowu"] = "高武",
  [":wq_skill_gaowu"] = "出牌阶段限一次，当你对其他角色造成伤害后，若你此阶段内对其造成过伤害，你可以令其失去1点体力。",
  ["$wq_skill_gaowu"] = "徒有力量是不够的，你得让它发挥该有的作用。",
  ["#wq_skill_gaowu_prompt"] = "高武：你可以令%dest失去1点体力",
  ["~wq_zhuoya"] = "我不能……倒在这里……",
}

-- 禁闭者：卡斯洛
local wq_kasiluo = General:new(extension, "wq_kasiluo", "qun", 4, 4, General.Female)
-- 技能：暗器
local wq_skill_anqi = fk.CreateTriggerSkill{
  name = "wq_skill_anqi",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and not player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for i = 1, 3, 1 do
      local cards = room:askForCard(player, 1, player:getHandcardNum(), false, self.name, true, ".", "#wq_skill_anqi_"..i.."-cards")
      if #cards > 0 then
        for _, id in ipairs(player.player_cards[Player.Hand]) do
          local card = Fk:getCardById(id)
          if table.contains(cards, id) then
            for j = 1, 3, 1 do
              room:setCardMark(card, "@@wq_skill_anqi_"..j, 0)
            end
            room:setCardMark(card, "@@wq_skill_anqi_"..i, 1)
          end
        end
      end
    end
  end,
  refresh_events = {fk.AfterCardsMove, fk.EventLoseSkill, fk.CardUsing, fk.TargetSpecified},
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return true
    elseif event == fk.EventLoseSkill then
      return target == player and data == self
    elseif event == fk.CardUsing then
      return target == player and data.card:getMark("@@wq_skill_anqi_2") > 0
    elseif event == fk.TargetSpecified then
      return target == player and data.card:getMark("@@wq_skill_anqi_3") > 0
    else
      return false
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.toArea ~= Card.Processing then
          for _, info in ipairs(move.moveInfo) do
            room:setCardMark(Fk:getCardById(info.cardId), "@@wq_skill_anqi_1", 0)
            room:setCardMark(Fk:getCardById(info.cardId), "@@wq_skill_anqi_2", 0)
            room:setCardMark(Fk:getCardById(info.cardId), "@@wq_skill_anqi_3", 0)
          end
        end
      end
    elseif event == fk.EventLoseSkill then
      for _, id in ipairs(player.player_cards[Player.Hand]) do
        room:setCardMark(Fk:getCardById(id), "@@wq_skill_anqi_1", 0)
        room:setCardMark(Fk:getCardById(id), "@@wq_skill_anqi_2", 0)
        room:setCardMark(Fk:getCardById(id), "@@wq_skill_anqi_3", 0)
      end
    elseif event == fk.CardUsing and data.card:getMark("@@wq_skill_anqi_2") > 0 then
      if data.card.is_damage_card then
        data.additionalDamage = (data.additionalDamage or 0) + 1
      end
    elseif event == fk.TargetSpecified and data.card:getMark("@@wq_skill_anqi_3") > 0 then
      local to = room:getPlayerById(data.to)
      room:addPlayerMark(to, "@wq_mark_gandian", math.min(to.hp))
    end
  end,
}
local wq_skill_anqi_targetmod = fk.CreateTargetModSkill{
  name = "#wq_skill_anqi_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill("wq_skill_anqi") and card:getMark("@@wq_skill_anqi_1") > 0 then
      return 999
    end
  end,
  distance_limit_func =  function(self, player, skill, card)
    if player:hasSkill("wq_skill_anqi") and card:getMark("@@wq_skill_anqi_1") > 0 then
      return 999
    end
  end,
}
wq_skill_anqi:addRelatedSkill(wq_skill_anqi_targetmod)
-- 技能：赋能
local wq_skill_funeng = fk.CreateTriggerSkill{
  name = "wq_skill_funeng",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (data.card:getMark("@@wq_skill_anqi_1") > 0 or data.card:getMark("@@wq_skill_anqi_2") > 0 or data.card:getMark("@@wq_skill_anqi_3") > 0)
      and player.phase == Player.Play and player:usedSkillTimes(self.name, Player.HistoryPhase) < 3
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#wq_skill_funeng_prompt")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:drawCards(player, 1, self.name)
  end,
}
-- 卡斯洛的技能
wq_kasiluo:addSkill(wq_skill_anqi)
wq_kasiluo:addSkill(wq_skill_funeng)
-- 卡斯洛的翻译
Fk:loadTranslationTable{
  ["wq_kasiluo"] = "卡斯洛",
  ["#wq_kasiluo"] = "物质赋能",
  ["designer:wq_kasiluo"] = "妙霄",
  ["cv:wq_kasiluo"] = "官方",
  ["illustrator:wq_kasiluo"] = "官方",
  ["wq_skill_anqi"] = "暗器",
  [":wq_skill_anqi"] = "出牌阶段开始时，你可以依次为任意手牌添加以下三种暗器标记：1.「飞刀」：无距离和次数限制；2.「手雷」：造成的伤害+1；3.「硬币」：指定目标后令其获得X枚「感电」标记（X为其体力值且至多为5）。每张手牌至多只能存在一种暗器标记。"
  ..Wqc.getTranslateInNewLine("#wq_common_mark_gandian_description"),
  ["$wq_skill_anqi"] = "尝尝我的“大宝贝”们吧！",
  ["wq_skill_anqi_1"] = "飞刀",
  ["@@wq_skill_anqi_1"] = "飞刀",
  ["#wq_skill_anqi_1-cards"] = "暗器：你可以为任意张手牌分配「飞刀」标记（无距离和次数限制）",
  ["wq_skill_anqi_2"] = "手雷",
  ["@@wq_skill_anqi_2"] = "手雷",
  ["#wq_skill_anqi_2-cards"] = "暗器：你可以为任意张手牌分配「手雷」标记（造成的伤害+1）",
  ["wq_skill_anqi_3"] = "硬币",
  ["@@wq_skill_anqi_3"] = "硬币",
  ["#wq_skill_anqi_3-cards"] = "暗器：你可以为任意张手牌分配「硬币」标记（指定目标后令其获得X枚「感电」标记，X为其体力值且至多为5）",
  ["wq_skill_funeng"] = "赋能",
  [":wq_skill_funeng"] = "出牌阶段限三次，当你使用有暗器标记的牌时，你可以摸一张牌。",
  ["$wq_skill_funeng"] = "哈！等着被疯狗撕碎吧！",
  ["#wq_skill_funeng_prompt"] = "赋能：你可以摸一张牌",
  ["~wq_kasiluo"] = "哈……角斗士死也该……死在战场上……",
}

return extension